﻿using NewRen.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace NewRen.Areas.Mobile.Controllers
{
    public class BaseController : Controller
    {
        public DB db = new DB();

        public log4net.ILog log = log4net.LogManager.GetLogger("myLogger");

        public BaseController() { }

        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            if (User.Identity.IsAuthenticated)
            {
                CurrentUser = (from u in db.Users
                               where u.UserName == User.Identity.Name
                               select u).SingleOrDefault();
                ViewBag.CurrentUser = CurrentUser;
            }
            else
            {
                ViewBag.CurrentUser = null;
            }
            ViewBag.SID = requestContext.HttpContext.Session["SID"].ToString();
        }


        public Models.User CurrentUser { get; set; }

        public ActionResult Message(string msg)
        {
            return RedirectToAction("Info", "Shared", new { msg = msg });
        }
    }
}